package com.kly.user.serviceImpl.traffic.forceConnect;

import com.fqgj.common.api.Response;
import com.kly.user.config.NacosValueConfig;
import com.kly.user.db.entity.IssueConfigEntity;
import com.kly.user.db.entity.IssueUsersDetailEntity;
import com.kly.user.db.entity.IssueUsersEntity;
import com.kly.user.db.entity.UserEntity;
import com.kly.user.enums.AppCodeEnum;
import com.kly.user.enums.AppEnum;
import com.kly.user.service.UserTrafficSourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class PPFc extends FcBase {

    @PostConstruct
    public void init() {
        FcTrafficHandler.fcBaseMap.put(AppEnum.PP.getUserAppFlag(), this);
    }

    @Autowired
    NacosValueConfig nacosValueConfig;

    @Autowired
    UserTrafficSourceService userTrafficSourceService;

    @Override
    public List<IssueUsersDetailEntity> getFilteredRes(List<IssueUsersDetailEntity> userEntities) {
        if (!nacosValueConfig.isPpFCCareMasterSwitch())
            //只取非自然用户
            return userEntities.stream().filter(item -> item.getTrafficType() == 2).collect(Collectors.toList());

        Integer trafficControlEnableSwitch = userTrafficSourceService.getTrafficControlEnableSwitch(AppCodeEnum.PP.getAppCode()).getData();
        if (trafficControlEnableSwitch == 0) {
            return userEntities;
        }

        return userEntities.stream().filter(item -> item.getTrafficType() == 2).collect(Collectors.toList());
    }
}
